#ifndef URAND_H
#define URAND_H
#include <bitset>
#include <cstddef>
#include <cstdlib>
#include <ctime>
using std::bitset;
using std::size_t;
/// @brief  实现一个产生随机数的程序，在范围内随机，获取过的值不会再随机到，知道范围全部获取过，重置
/// @tparam UpperBound 
template <size_t UpperBound>
class Urand
{
private:
    bitset<UpperBound> used;

public:
    Urand()
    {
        srand(time(0));
    }
    size_t operator()();
};
template <size_t UpperBound>
inline size_t Urand<UpperBound>::operator()()
{
    if (used.count() == UpperBound)
        used.reset();
    size_t newval;
    while (used[newval = rand() % UpperBound])
    {
    };
    used[newval] = true;
    return newval;
}

#endif // URAND_H ///:~